﻿// Create icon from specified url on point
function CreateMapMarker(map, url, width, height, lat, lng, description, hyperlink, behavior, title, opt_titlecolor) {  
  var icon = new GIcon();
  icon.image = url;
  icon.shadow = url;
  icon.iconSize = new GSize(width, height);
  icon.shadowSize = new GSize(width, height);
  icon.iconAnchor = new GPoint(width/2, height/2);
  icon.infoWindowAnchor = new GPoint(width/2, height/2);
  var marker = new GMarker(new GLatLng(lat,lng), icon);
  marker.hyperlink = hyperlink;
  
  if ((behavior == 1 || behavior == 3) && description != null && description != '') {
    GEvent.addListener(marker, "mouseover", function() {
      marker.openInfoWindowHtml(description);  
    });  
  }
  
  if ((behavior == 3 || behavior == 4) && hyperlink != null && hyperlink != '') {
    GEvent.addListener(marker, "click", function() {  
      window.open(marker.hyperlink);
    });
  }
  
  if (behavior == 2 && description != null && description != '') {
    GEvent.addListener(marker, "click", function() {  
      map.closeInfoWindow();
      marker.openInfoWindowHtml(description);
    });
  }
  
  //for title support requires include "MapTitle"
  if (title != null && title != '') {
    var oTitle = new MapTitle(title, new GLatLng(lat,lng), new GPoint(0, height), opt_titlecolor);
    map.addOverlay(oTitle);
  }

  map.addOverlay(marker);
  return marker;
}
